package com.atguigu.process.controller;

import com.atguigu.common.result.Result;
import com.atguigu.model.process.ProcessType;
import com.atguigu.process.service.ProcessTypeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags="审批类型相关接口")
@RestController
@RequestMapping("/admin/process/processType")
public class ProcessTypeController {
    @Autowired
    private ProcessTypeService processTypeService;

    @ApiOperation("分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<IPage<ProcessType>> pageQuery(@PathVariable Long page, @PathVariable Long limit){
        IPage<ProcessType> pageInfo = new Page<>(page,limit);
        processTypeService.page(pageInfo);
        return Result.ok(pageInfo);
    }

    @ApiOperation("根据id查询")
    @GetMapping("/get/{id}")
    public Result<ProcessType> getById(@PathVariable Long id){
        return Result.ok(processTypeService.getById(id));
    }

    @ApiOperation("添加审批类型")
    @PostMapping("/save")
    public Result save(@RequestBody ProcessType processType){
        processTypeService.save(processType);
        return Result.ok();
    }

    @ApiOperation("更新审批类型")
    @PutMapping("/update")
    public Result update(@RequestBody ProcessType processType){
        processTypeService.updateById(processType);
        return Result.ok();
    }

    @ApiOperation("根据id删除审批类型")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Long id){
        processTypeService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("查询所有审批类型")
    @GetMapping("/findAll")
    public Result<List<ProcessType>> findAll(){
        return Result.ok(processTypeService.list());
    }
}
